//some + concat
Array.prototype.myFlat=function(num=1){
    if(num<0) return this
    let res = [...this]
    while(num>0&&res.some(item=>Array.isArray(item))){
        res = [].concat(...res)
        num--
    }
    return res
}

let test = [1,2,3,[4,5,[6,7]]]

console.log(test.myFlat(1));